package com.mdd.admin.controller;

import com.mdd.admin.service.ProductCategoryService;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.ProductCategoryVo;
import com.mdd.admin.vo.RelationshipRecordListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.ProductCategory;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/productCategory")
@Api(tags = "产品分类")
public class productCategoryController {

    @Autowired
    private ProductCategoryService productCategoryService;

    /**
     * 分页查询
     * @param pageValidate
     * @param id
     * @return
     */
    @PostMapping("/list")
    public AjaxResult<PageResult<ProductCategory>> list(@Validated PageValidate pageValidate, @Validated Integer id) {
        PageResult<ProductCategory> list = productCategoryService.list(pageValidate,id);
        return AjaxResult.success(list);
    }

    /**
     * 获取上级分类
     * @param id
     * @return
     */
    @GetMapping("/getParentList/{id}")
    public AjaxResult<List<ProductCategoryVo>> getParentList(@PathVariable Integer id) {
        List<ProductCategoryVo> list = productCategoryService.list(id);
        return AjaxResult.success(list);
    }

    @PostMapping("/save")
    public AjaxResult<ProductCategory> save(@RequestBody ProductCategory productCategory) {
        return AjaxResult.success(productCategoryService.save(productCategory));
    }

    @PostMapping("/update")
    public AjaxResult<Boolean> update(@RequestBody ProductCategory productCategory) {
        return AjaxResult.success(productCategoryService.update(productCategory));
    }

    @GetMapping("/remove/{id}")
    public AjaxResult<Boolean> remove(@PathVariable Integer id) {
        return AjaxResult.success(productCategoryService.remove(id));
    }

    @GetMapping("/info/{id}")
    public AjaxResult<ProductCategory> info(@PathVariable Integer id) {
        return AjaxResult.success(productCategoryService.info(id));
    }
}
